package cn.edu.scau.cmi.chensicheng.client;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.chensicheng.adapter.Adaptee;
import cn.edu.scau.cmi.chensicheng.adapter.ClassAdapter;
import cn.edu.scau.cmi.chensicheng.adapter.ConcreteTarget;
import cn.edu.scau.cmi.chensicheng.adapter.ObjectAdapter;
import cn.edu.scau.cmi.chensicheng.adapter.Target;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class AdapterClient extends Application implements Initializable{
	
	@FXML
	private VBox vBox;
	@FXML
	private Button standardButton;
	@FXML
	private Button classButton;
	@FXML
	private Button objectButton;
	@FXML
	private TextArea textArea;
	
	@Override
	public void start(Stage primaryStage) throws IOException {
		VBox Box=FXMLLoader.load(getClass().getResource("../Adapter.fxml"));
		Scene scene=new Scene(Box);
		primaryStage.setScene(scene);
		primaryStage.setTitle("实验四适配器模式");
		primaryStage.show();
	}

	public static void main(String[] args) {
		launch(args);
	}
	
	public void initialize(URL url,ResourceBundle rb) {
		standardButton.setOnAction(e->{
			Target target=new ConcreteTarget();
			textArea.setText(target.request());
		});
		classButton.setOnAction(e->{
			Target target=new ClassAdapter();
			textArea.setText(target.request());
		});
		objectButton.setOnAction(e->{
			Target target=new ObjectAdapter(new Adaptee());
			textArea.setText(target.request());
		});
	}
}
